<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const type = "1";
      const map = new Map([
        [
          type == 1,
          (param) => {
            console.log(param);
          },
        ],
        [
          type == 2,
          (param) => {
            console.log(param);
          },
        ],
      ]);

      // 定义条件和处理函数的二维数组
      const conditions = [
        [
          1,
          (param) => {
            console.log(`Condition 1: ${param}`);
          },
        ],
        [
          2,
          (param) => {
            console.log(`Condition 2: ${param}`);
          },
        ],
        [
          3,
          (param) => {
            console.log(`Condition 3: ${param}`);
          },
        ],
      ];

      // 创建一个 Map 对象
      const conditionMap = new Map(conditions);

      // 定义一个函数来处理不同的条件
      function handleConditions(type, param) {
        // 获取对应的处理函数
        const handler = conditionMap.get(type);

        if (handler) {
          // 调用处理函数
          handler(param);
        } else {
          console.log(`No handler for type: ${type}`);
        }
      }

      // 测试
      const param = "Hello, World!";

      handleConditions(1, param); // 输出: Condition 1: Hello, World!
      handleConditions(2, param); // 输出: Condition 2: Hello, World!
      handleConditions(3, param); // 输出: Condition 3: Hello, World!
      handleConditions(4, param); // 输出: No handler for type: 4

      export default {
        data() {
          return {
            user: {
              name: "John Doe",
              age: 30,
              address: "123 Main St",
            },
          };
        },
        methods: {
          clearUser() {
            Object.keys(this.user).forEach((key) => {
              this.user[key] = key === "age" ? null : "";
            });
          },
          haha(arr, prop) {
            const set = new Set();
            return arr.filter((v) => {
              return !set.has(v[prop]) && set.add(v[prop]);
            });
          },
        },
      };
    </script>
  </body>
</html>
